/**
 * 检查项目接口
 */

const BlockChainApp = require("../services/BlockChainApp");
const CaseReportContract = require("../services/contracts/CaseReportContract");
const CheckProjectContract = require("../services/contracts/CheckProjectContract");
const { totalUser } = require("../services/contracts/UserContract");
const UserContract = require("../services/contracts/UserContract");
const Message = require("../services/Message");

// const Message = require("../services/Message")

module.exports = {
 // 新增
createProject: async function(req, res){
    var param = req.body.data
    console.log("new record: ", param)
    // var instance = await BlockChainApp.contracts.CaseRecords.deployed()
    CheckProjectContract.addCheckProject(param)
    .then(
        data=>{
            return res.json(Message.success("新增检查项目信息完成"))
        }
    )
    .catch(
        err=>{
            console.log(err)
            return res.json(Message.error("新增检查项目信息错误"))
        }
    )
},

// 查看所有
getAllProject: async function(req, res){
    // var instance = await BlockChainApp.contracts.CaseRecords.deployed()

    PrescriptionContract.getAllProject()
    .then(
        data=>{
            return res.json(Message.success(data))
        }
    )
    .catch(
        err=>{
            console.log(err)
            return res.json(Message.error("获取检查项目信息错误"))
        }
    )
},

// 条件查询
getProjectWithCondition: async function(req, res){
    var param = req.body.data
    PrescriptionContract.getProjectWithCondition(param)
    .then(data=>{
        return res.json(Message.success(data))
    })
    .catch(error=>{
        console.log(error)
        return res.json(Message.error("获取检查项目信息错误"))
    })
},

// 更新
updateProject: async function(req, res){
    var param = req.body.data
    PrescriptionContract.updateProject(param)
    .then(data=>{
        // console.log("更新完成", data)
        return res.json(Message.success(data))
    })
    .catch(error=>{
        console.log("error: ", error)
        return res.json(Message.error("更新检查项目信息错误"))
    })
},
}